﻿using System.Text;
using System.Web.Mvc;
using XXS.Common.ActionResult;

namespace XXS.Common.ControllerExt
{
    public class BaseController : Controller
    {
        protected internal JsonNetResult JsonNet(object data)
        {
            return JsonNet(data, null /* contentType */, null /* contentEncoding */, JsonRequestBehavior.DenyGet);
        }

        protected internal JsonNetResult JsonNet(object data, string contentType)
        {
            return JsonNet(data, contentType, null /* contentEncoding */, JsonRequestBehavior.DenyGet);
        }

        protected internal virtual JsonNetResult JsonNet(object data, string contentType, Encoding contentEncoding)
        {
            return JsonNet(data, contentType, contentEncoding, JsonRequestBehavior.DenyGet);
        }

        protected internal JsonNetResult JsonNet(object data, JsonRequestBehavior behavior)
        {
            return JsonNet(data, null /* contentType */, null /* contentEncoding */, behavior);
        }

        protected internal JsonNetResult JsonNet(object data, string contentType, JsonRequestBehavior behavior)
        {
            return JsonNet(data, contentType, null /* contentEncoding */, behavior);
        }

        protected internal virtual JsonNetResult JsonNet(object data, string contentType, Encoding contentEncoding,
            JsonRequestBehavior behavior)
        {
            return new JsonNetResult
            {
                Data = data,
                ContentType = contentType,
                ContentEncoding = contentEncoding,
                JsonRequestBehavior = behavior
            };
        }

        ///// <summary>
        /////     返回ModelState错误信息,并支持HttpGet请求
        ///// </summary>
        ///// <returns></returns>
        //protected System.Web.Mvc.ActionResult ModelStateErrorToExtJson()
        //{
        //    return JsonNet(new { }.ToExtFailure(ModelState.GetModelErrorString()), JsonRequestBehavior.AllowGet);
        //}

        protected System.Web.Mvc.ActionResult ExtJSSuccessResult()
        {
            return JsonNet(ExtJsonHelper.GetExtSuccessResult());
        }
        protected System.Web.Mvc.ActionResult ExtJSFailureResult()
        {
            return JsonNet(ExtJsonHelper.GetExtFailureResult());
        }
    }
}